#include "xjil.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

void test_json(const char *json, size_t len)
{
    value_t *v = xjil_value_new(TYPE_NULL);
    xjil_parse(v, json, len);
    xjil_value_del(v);
}

void test_syntax()
{

}

int main(int argc, char **argv)
{
    int i, fd;
    char *src;
    argc--;
    argv++;

    int poolsize = 256 * 1024; // arbitrary size

    if ((fd = open(*argv, 0)) < 0)
    {
        printf("could not open(%s)\n", *argv);
        return -1;
    }

    if (!(src = malloc(poolsize)))
    {
        printf("could not malloc(%d) for source area\n", poolsize);
        return -1;
    }

    // read the source file
    if ((i = read(fd, src, poolsize - 1)) <= 0)
    {
        printf("read() returned %d\n", i);
        return -1;
    }
    src[i] = 0; // add EOF character

    close(fd);

    test_json(src, i);

    return 0;
}